package com.rrd.dw.mr.gzip.kafka;

import java.io.IOException;
import java.util.Date;
import java.util.regex.Pattern;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import com.rrd.dw.utils.DateUtil;
import com.ucredit.babel.common.model.Job;
import com.ucredit.babel.common.model.pcac.PcacRiskInfo;
import com.ucredit.babel.common.model.pcac.RiskInfo;

/**
 * 小微平台风险信息
 * @author liubaoxin
 */
@Deprecated
public class PcacRiskInfoParse {
	public static final String CRT001 =  "\001";
	public static final Pattern CRT001_PATTERN =  Pattern.compile("\001");
	private String timestamstr="";
	private String job_id ="";
	private String system_id ="";
	private StringBuilder sb = new StringBuilder(500);
	private  Text val = new Text();
	 private Text key_text = new Text("pcac_risk_data");
	
	/**
	 * 小微平台风险信息
	 * @param userBehavior
	 * @throws InterruptedException 
	 * @throws IOException 
	 */
	public  void parsePcacRisk(Context context,PcacRiskInfo pcacRiskInfo) throws IOException, InterruptedException{
		 
    	Job job = pcacRiskInfo.getJob();
    	RiskInfo riskInfo = pcacRiskInfo.getRiskInfo();
    	 
    	sb.delete(0,sb.length());
    	//job_id
    	this.job_id = job.getJobID()==null?"":job.getJobID();
    	//system_id
    	this.system_id = job.getSystemID()==null?"":job.getSystemID().toString();
    	//数据时间 
    	this.timestamstr=pcacRiskInfo.getTimestamp()==null?"":DateUtil.formateDateStr(new Date(pcacRiskInfo.getTimestamp()));
 
    	sb.append(job_id).append(CRT001);
    	sb.append(system_id).append(CRT001);
    	sb.append(this.timestamstr).append(CRT001);
    	
    	sb.append(riskInfo.getName()==null?"":riskInfo.getName()).append(CRT001);
    	sb.append(riskInfo.getIdno()==null?"":riskInfo.getIdno()).append(CRT001);
    	sb.append(riskInfo.getPeriod()==null?"":riskInfo.getPeriod()).append(CRT001);
    	sb.append(riskInfo.getData()==null?"":riskInfo.getData()).append(CRT001);
    	
    	//爬取开始时间
    	sb.append(job.getStartTime()==null?"":DateUtil.formateDateStr(job.getStartTime())).append(CRT001);
    	val.set(sb.toString());
        context.write(key_text, val);
    
    	 
	}
	
	
	
	
	
}
